package vip.liux.contracts;

import org.apache.commons.lang3.tuple.Pair;
import org.springframework.beans.factory.ObjectProvider;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import vip.liux.contracts.infrastructure.localmsg.LocalMessageAspect;
import vip.liux.contracts.infrastructure.pay.PayClientFactory;
import vip.liux.contracts.infrastructure.pay.impl.AbstractPayClient;
import vip.liux.contracts.infrastructure.pay.impl.PayClientFactoryImpl;
import vip.liux.contracts.shared.enums.pay.PayChannelCode;
import vip.liux.contracts.shared.properties.FilesProperties;

import java.util.function.Supplier;

@Configuration(proxyBeanMethods = false)
@EnableConfigurationProperties(FilesProperties.class)
@ComponentScan({
        "vip.liux.contracts.models",
        "vip.liux.contracts.security"
})
public class ContractsAutoConfiguration {

    /**
     * LocalMessageAspect bean for handling local message operations.
     * This aspect will intercept methods related to local message processing.
     *
     * @return a new instance of LocalMessageAspect
     */
    @Bean
    public LocalMessageAspect localMessageAspect() {
        return new LocalMessageAspect();
    }

    @Bean
    public PayClientFactory payClientFactory(ObjectProvider<Supplier<Pair<PayChannelCode, Class<? extends AbstractPayClient<?>>>>> provider) {
        return new PayClientFactoryImpl(provider);
    }
}
